// pages/UserStatistics/PersonnelDetails/PersonnelDetails.js
const controllers = require('../../controllers/controllerIndex.js').controller;
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs: [
      {
        name: "服务订单",
        type: 0,
        isActive: true
      },
      {
        name: "商品订单",
        type: 1,
        isActive: false
      },
      {
        name: "云商品订单",
        type: 2,
        isActive: false
      },

      {
        name: "提成结算",
        type: 3,
        isActive: false
      }
    ],
    status:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    

  let  date = new Date();
  

  let year = date.getFullYear()
  let month = date.getMonth() + 1
  let day = date.getDate()
    controllers.staffDetail({
       sessionId:wx.getStorageSync('token'),
       shopId:wx.getStorageSync('shopId'),
       shopAccountId:options.id,
       head:options.head
    }).then(res =>{
     
      this.setData({
        nowDate:year+'-'+month+'-'+day,
        userInfo:res.data,
        shopAccountId:options.id
      })
     
    })
    this.checkOrder(options.id)
  },

  clikcTabs(e) {
    const   index   = e.currentTarget.dataset.index
   
    let tabs = this.data.tabs
    
    tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false);
    this.setData({
      tabs,
      status:index
    })
    if(index!=3)
     this.checkOrder()
     else
     this.commissionList()
  },

  checkOrder(id){
    let that =this
    let status=6;
    if(that.data.status==0){
      status=6
    }else if(that.data.status==1){
      status=1
    }else{
      status=7
    }
    controllers.staffPage({
      sessionId:wx.getStorageSync('token'),
      shopId:wx.getStorageSync('shopId'),
      shopAccountId:id||that.data.shopAccountId,
      pageSize:20,
      pageNumber:1,
      type:status||6

   }).then(res =>{
    that.setData({
      orderList:res.data.list
    })
   })

    
  },
  commissionList(id){
    let that =this
    controllers.commissionList({
      sessionId:wx.getStorageSync('token'),
      shopAccountId:id||that.data.shopAccountId,
   }).then(res =>{

    //code	0出错1成功2请登录3需绑定手机号
    if(res.code==1)
    that.setData({
      commissionList:res.data
    })
   
   })
  },
  pDetails() {
    wx.navigateTo({
      url: '../Commission/CommissionDetalis'
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
   // onShareAppMessage: function () {

  // }
})